﻿<UserControl xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Encoder="clr-namespace:Silverlight.Media.Encoder;assembly=Silverlight.Media.Encoder"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:ViewModels="clr-namespace:SilverlightWebcamEncoder.ViewModels"
             xmlns:Controls="clr-namespace:SilverlightWebcamEncoder.Controls"
             xmlns:Behaviors="clr-namespace:SilverlightWebcamEncoder.Behaviors"
             xmlns:Views="clr-namespace:SilverlightWebcamEncoder.Views"
             x:Class="SilverlightWebcamEncoder.Views.EncoderView"
             mc:Ignorable="d"
             d:DesignHeight="527.5"
             d:DesignWidth="613.5" TextOptions.TextHintingMode="Animated">
    <UserControl.DataContext>
        <ViewModels:EncoderViewModel />
    </UserControl.DataContext>
    <Grid x:Name="LayoutRoot"
          Margin="0">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="Common">
                <VisualStateGroup.Transitions>
                	<VisualTransition GeneratedDuration="0:0:0.8" />
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Encoding" >
                	<Storyboard>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="checkBox">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Thickness>0,1,0,0</Thickness>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                	</Storyboard>
                </VisualState>
                <VisualState x:Name="MediaStarted">
                	<Storyboard>
                		<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="stackPanel" d:IsOptimized="True"/>
                		<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="stackPanel">
                			<DiscreteObjectKeyFrame KeyTime="0">
                				<DiscreteObjectKeyFrame.Value>
                					<Thickness>0,9,0,0</Thickness>
                				</DiscreteObjectKeyFrame.Value>
                			</DiscreteObjectKeyFrame>
                		</ObjectAnimationUsingKeyFrames>
                	</Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Controls:AnimatedRings x:Name="animatedRings"
        	Margin="-100,-100,-100,-50" Visibility="Collapsed" />
        <Grid x:Name="grid"
              Margin="0"
              HorizontalAlignment="Center"
              VerticalAlignment="Center">
            <Grid x:Name="EncodingStuff"
                  Margin="0"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center" Width="480" Height="360">
                <Grid.Projection>
                    <PlaneProjection />
                </Grid.Projection>
                <Grid.RowDefinitions>
                	<RowDefinition Height="320" />
                	<RowDefinition Height="60" />
                </Grid.RowDefinitions>
                <StackPanel x:Name="stackPanel"
                            Margin="0,-40,0,0"
                            d:LayoutOverrides="Width"
                            Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Top" Orientation="Horizontal">
                	<CheckBox x:Name="checkBox" Content="Network Streaming"
                		IsChecked="{Binding NetworkStream, Mode=TwoWay}"
                		IsThreeState="False"
                		Foreground="#FF2E2E2E" VerticalAlignment="Top" FontFamily="Segoe UI" FontSize="13.333" Margin="0,-2,0,0" Style="{StaticResource CheckBoxStyle}" />
                	<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="21,0,0,0" HorizontalAlignment="Left">
                		<TextBlock Text="Streaming Port "
                			Foreground="#FF2E2E2E" d:LayoutOverrides="Width" FontFamily="Segoe UI" FontSize="13.333" />
                		<my:NumericUpDown Maximum="65530"
                			Minimum="1000"
                			Value="{Binding TcpPort, Mode=TwoWay}"
                			Foreground="#FF2E2E2E"
                			BorderBrush="{x:Null}" Margin="0" HorizontalAlignment="Left" FontFamily="Segoe UI" FontSize="13.333"  />
                	</StackPanel>
                </StackPanel>
                <Border BorderThickness="1" Background="Black" CornerRadius="4" Margin="10" BorderBrush="Black">
            		<Border.Effect>
            			<DropShadowEffect BlurRadius="15" ShadowDepth="0"/>
            		</Border.Effect>
            	</Border>
                <Grid Margin="10">
                    <Encoder:EncoderElement IsEncoding="{Binding IsEncoding, Mode=TwoWay}"
                                            EncoderProfileData="{Binding EncoderProfileData, Mode=TwoWay}"
                                            EncodeFps="{Binding EncodeFps, Mode=TwoWay}"
                                            OutputFilename="{Binding OutputFilename, Mode=TwoWay}"
                                            InstallationPath="{Binding InstallationPath, Mode=TwoWay}"
                                            NetworkStream="{Binding NetworkStream, Mode=TwoWay}"
                                            TcpPort="{Binding TcpPort, Mode=TwoWay}"
                                            x:Name="encoder"
                                            Style="{StaticResource EncoderElementStyle}"
                                            BorderThickness="1"
                                            Background="Black" d:IsHidden="True" BorderBrush="White">
                        <i:Interaction.Triggers>
                        	<i:EventTrigger EventName="EncoderPrepared">
                        		<ei:ChangePropertyAction TargetObject="{Binding ElementName=button}"
                        			PropertyName="Opacity"
                        			Value="0" />
                        		<ei:ChangePropertyAction TargetObject="{Binding ElementName=toggleButton}"
                        			PropertyName="Visibility" />
                        		<ei:GoToStateAction StateName="MediaStarted"/>
                        	</i:EventTrigger>
                        	<i:EventTrigger EventName="StartEncodeFailed">
                        		<ei:ChangePropertyAction TargetObject="{Binding ElementName=toggleButton}"
                        			PropertyName="IsChecked"
                        			Value="False" />
                        	</i:EventTrigger>
                        	<i:EventTrigger EventName="EncodingStarted">
                        		<ei:ChangePropertyAction TargetObject="{Binding ElementName=animatedRings}"
                        			PropertyName="Visibility" >
                        			<ei:ChangePropertyAction.Value>
                        				<Visibility>Visible</Visibility>
                        			</ei:ChangePropertyAction.Value>
                        		</ei:ChangePropertyAction>
                        		<ei:GoToStateAction StateName="Encoding"/>
                        		
                        	</i:EventTrigger>
                        	<i:EventTrigger EventName="EncodingStopped">
                        		<ei:ChangePropertyAction TargetObject="{Binding ElementName=animatedRings}"
                        			PropertyName="Visibility">
                        			<ei:ChangePropertyAction.Value>
                        				<Visibility>Collapsed</Visibility>
                        			</ei:ChangePropertyAction.Value>
                        		</ei:ChangePropertyAction>
                        		<i:InvokeCommandAction Command="{Binding EncodingStopped}" />
                        		<ei:GoToStateAction StateName="MediaStarted"/>
                        	</i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Encoder:EncoderElement>
                    <Button x:Name="button"
                            Content="Show Camera"
                            Click="Button_Click"
                            VerticalAlignment="Center"
                            Style="{StaticResource PlayButton}"
                            HorizontalAlignment="Center" />
                    <ToggleButton x:Name="toggleButton"
                                  Content="   rec."
                                  IsChecked="{Binding IsEncoding, Mode=TwoWay}"
                                  IsThreeState="False"
                                  Style="{StaticResource RecordToggleButtonStyle}"
                                  Margin="0,0,10,10"
                                  d:LayoutOverrides="Width, Height"
                                  HorizontalAlignment="Right"
                                  VerticalAlignment="Bottom" Foreground="White" FontFamily="Segoe UI" FontWeight="Bold" Visibility="Collapsed" />
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
